package com.example.mform.controller;

import com.example.mform.entity.Choice;
import com.example.mform.service.ChoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/choice")
public class ChoiceController {

    @Autowired
    private ChoiceService choiceService;

    @GetMapping("/findAll")
    public List<Choice> findAll() {
        return choiceService.findAll();
    }

    @GetMapping("/findById/{id}")
    public Choice findById(@PathVariable("id") Long id) {
        return choiceService.findById(id);
    }

    @PostMapping("/save")
    public void save(@RequestBody Choice choice) {
        choiceService.save(choice);
    }

    @PutMapping("/update")
    public void update(@RequestBody Choice choice) {
        choiceService.save(choice);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        choiceService.deleteById(id);
    }
}
